<?php
$notLocalizedTypes=array("Date","File","Flash","Image","InternalLink","Map","Query","YoutubeVideo");

reloadAuthoringTemplate($currentObject->id);


	if (true){
// i should map authoringtemplate with default presentation
	$authoringTempateId=getObjByKey("portal_content","authoringtemplateId","id",getParameter("keyvalue"));
	
	
	
	foreach ($_REQUEST as $param_name => $param_val) {
		//echo strpos($param_name,"editor_")." ".$param_name."<br>";
		if (!(strpos($param_name,"editor_")===false))
		{
	
	
			$type=substr($param_name,strrpos($param_name,"_")+1);
			
			$localized="_".$LANG."_";
			if ( in_array($type,$notLocalizedTypes) ) $localized="";
			
			$keycontentvalue=$type.$localized."value";
	
			$elementId=getObjByKey("portal_authoringtemplate_elements","id","authoringId",$authoringTempateId,"name",str_replace("_".$type,"",str_replace("editor_","",$param_name)));
	
	
	
			$Sql="update ".getParameter("tabletosave")." set $keycontentvalue='".$param_val."' where ".getParameter("key")."=".getParameter("keyvalue")." and authoringtemplate_elementId=$elementId;";
		//	echo $Sql."<br/>";
			$GLOBALS["conn"]->Execute($Sql);
	
		}
	}
	

$sSql="SELECT
portal_authoringtemplate_elements.`name` as element,
portal_authoringelement.`name` as type,
portal_contentvalues.*
FROM
portal_contentvalues
INNER JOIN portal_authoringtemplate_elements ON portal_authoringtemplate_elements.id = portal_contentvalues.authoringtemplate_elementId
INNER JOIN portal_authoringelement ON portal_authoringtemplate_elements.elementId = portal_authoringelement.id
WHERE
portal_contentvalues.contentId = ".$currentObject->id;


//echo $sSql;

?>

<div id="gmp_portal_contentvalues" class="ewGridMiddlePanel">
<?php 

$rs=$GLOBALS["conn"]->Execute($sSql);

while ( !$rs->EOF)  {



    ?>
<label><?=$rs->fields["element"]?> (<?php echo $rs->fields["type"]; ?>	)</label>
<?php 
$fieldId="editor_".$rs->fields["element"]."_".$rs->fields["type"];

if (in_array($rs->fields["type"], $notLocalizedTypes) )
{
	
	 

	if ($rs->fields["type"]=="Map") $value=$rs->fields[$rs->fields["type"]."_Longvalue"]."/".$rs->fields[$rs->fields["type"]."_Latvalue"];
	else $value=$rs->fields[$rs->fields["type"]."value"];
}
	else
$value=$rs->fields[$rs->fields["type"]."_".$LANG."_value"];

if ($rs->fields["type"]=="TextField")
{
?>
<input type="text" size="80" name="<?=$fieldId?>" id="<?=$fieldId?>" style="width: 80%"  value="<?=$value?>"/>
<?php }
elseif ($rs->fields["type"]=="RichText")
{
?>
<textarea rows="5" cols="80"  name="<?=$fieldId?>" id="<?=$fieldId?>"><?=$value?></textarea>
<script type="text/javascript">
CKEDITOR.replace( '<?=$fieldId?>' );

</script>

<?php
if (endsWith ($fieldId, "_AR" )) Yamlify ( $fieldId ); 
}elseif ($rs->fields["type"]=="TextArea")
{
?>
<textarea rows="5" cols="80"  name="<?=$fieldId?>" id="<?=$fieldId?>" style="width: 80%"><?=$value?></textarea>
<?php } elseif ($rs->fields["type"]=="Date")
{
?>
<input class="hasDatepicker" type="text" size="20" name="<?=$fieldId?>" id="<?=$fieldId?>"  value="<?=$value?>" />
<script>
				  $(function() {
			
				    $( "#<?=$fieldId?>" ).datepicker({ dateFormat: "yy-mm-dd" });
				  });
				  			</script>
<?php }  elseif ($rs->fields["type"]=="Image")
{

	$type = getObjByKey ( "portal_filetype", "typename", "id", "image" ); // $currentObject->imagevalue_ext
	$type="Images";
	?>
	<input type="text"  name="<?=$fieldId?>" id="<?=$fieldId?>" value="<?=$value?>" />		
	
	
	<div class="pickercontainer">
		
		<div class="picker">
		<a
			href="javascript:pickfile('<?=$fieldId?>','<?php echo getFilesPath('image',false); ?>','<?=$type?>');"><img
			src="images/pick.png"></a></div>
	<img class="pickedimage" alt="no-image" id="<?=$fieldId?>_image"	src="<?=getFileManagerImage($value)?>">
	

		
	</div>
	<div id="picker_<?=$fieldId?>"></div>
	<script type="text/javascript">
				$("#<?=$fieldId?>").hide();
			 </script>
	<?php
} elseif ($rs->fields["type"]=="Query")
{
?>
<textarea rows="5" cols="80"  name="<?=$fieldId?>" id="<?=$fieldId?>" style="width: 80%" >Example : SELECT 1 FROM DUAL</textarea>
<?php }elseif ($rs->fields["type"]=="YoutubeVideo")
{
	if ($value="") $value="Enter Youtube video Link Here";
?>
<input type="text" size="80" name="<?=$fieldId?>" id="<?=$fieldId?>" style="width: 80%"   value="<?=$value?>"  />
<?php }elseif ($rs->fields["type"]=="Map")
{
?>

<input type="text" size="300" name="<?=$fieldId?>" id="<?=$fieldId?>" style="width: 80%" value="Enter Google Map Link Here" />

<?php }elseif($rs->fields["type"]=="File")
{
	$uploadPath="";
	?>
<input type="hidden" size="80" name="<?=$fieldId?>" id="<?=$fieldId?>" />
	<script type="text/javascript">
	
	function setuploadvalue_<?=$fieldId?>(filename,id)
	     {
	
	         $("#"+id).val(filename);
	         $("#"+id+"_link").attr("href","/<?=$uploadPath ?>"+filename);
	         $("#"+id+"_link").text(filename);
	     }
	</script>
	<a target="_blank" href="#" id="<?=$fieldId?>_link"><?=htmlspecialchars("xxx")?></a>
	<br />
	<iframe
		src="/portlet.php?app=system&operation=fileUpload&path=<?=$uploadPath ?>&field=<?=$fieldId?>"
		id="iframeupload" height="40px" width="80%" frameborder="0"></iframe>
	<?php
 }elseif($rs->fields["type"]=="Flash")
{
	$uploadPath="";
	?>
<input type="hidden" size="80" name="<?=$fieldId?>" id="<?=$fieldId?>" />
	<script type="text/javascript">
	
	function setuploadvalue_<?=$fieldId?>(filename,id)
	     {
	
	         $("#"+id).val(filename);
	         $("#"+id+"_link").attr("href","/<?=$uploadPath ?>"+filename);
	         $("#"+id+"_link").text(filename);
	     }
	</script>
	<a target="_blank" href="#" id="<?=$fieldId?>_link"><?=htmlspecialchars("xxx")?></a>
	<br />
	<iframe
		src="/portlet.php?app=system&operation=fileUpload&path=<?=$uploadPath ?>&field=<?=$fieldId?>"
		id="iframeupload" height="40px" width="80%" frameborder="0"></iframe>
	<?php
}

?>


     <!-- <?=$fieldId?>				
        

    <?php echo $rs->fields["id"]; ?><img border="0" src="./images/icons/ButterflyPortal-change.png" title="Modifier">	 -->   	
<br clear="all"/>
<?php
    $rs->MoveNext();
}

?>
<input type="hidden" name="tabletosave" value="portal_contentvalues">
<input type="hidden" name="key" value="contentId">
<input type="hidden" name="keyvalue" value="<?=getParameter("ButterflyPortal_sys_rec")?>">
<a href="#">Preview Content</a>

</div>

<?php } ?>
